package com.szd.qiongyou20.community.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.szd.qiongyou20.R;
import com.szd.qiongyou20.community.bean.RecommendBean;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by SZD on 2016/12/29.
 */

public class Recon_GridView_Adapter extends BaseAdapter {

    private Context mContext;
    private List<RecommendBean.DataBean.IconListBean> mList;

    public Recon_GridView_Adapter(Context context, List<RecommendBean.DataBean.IconListBean> list) {
        mContext = context;
        mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_recon_gridview, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        String icon_pic = mList.get(position).getIcon_pic();
        String icon = mList.get(position).getIcon();

        Glide.with(mContext).load(icon_pic).into(holder.mImageViewIcon);
        holder.mTextViewNameForIcon.setText(icon);

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.imageView_icon)
        ImageView mImageViewIcon;
        @Bind(R.id.textView_name_for_icon)
        TextView mTextViewNameForIcon;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
